﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;

namespace NLarge.CustomConverters
{
    public class TimeSpanToDoubleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is TimeSpan)) return 0d;
            TimeSpan timeSpan = (TimeSpan)value;
            return timeSpan.TotalMinutes;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is double)) return TimeSpan.Zero;

            double d = (double)value;
            return TimeSpan.FromMinutes(d);

        }

    }
}
